<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns:yui="http://yuilibrary.com/rdf/1.0/yui.rdf#">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<title>API: dom   selector-css2.js  (YUI Library)</title>

	<link rel="stylesheet" type="text/css" href="assets/reset-fonts-grids-min.css" />
	<link rel="stylesheet" type="text/css" href="assets/api.css" />

    <script type="text/javascript" src="assets/api-js"></script>
    <script type="text/javascript" src="assets/ac-js"></script>
</head>

<body id="yahoo-com">

<div id="doc3" class="yui-t2">
	<div id="hd">
        <h1><a href="http://developer.yahoo.com/yui/" title="Yahoo! UI Library">Yahoo! UI Library</a></h1>
        <h3>dom&nbsp; <span class="subtitle">3.0.0b1</span></h3>
        <a href="./index.html" title="Yahoo! UI Library">Yahoo! UI Library</a> 
            &gt; <a href="./module_dom.html" title="dom">dom</a>
                
                 &gt; selector-css2.js (source view) 
        <form onsubmit="return false">
            <div id="propertysearch">
                Search: <input autocomplete="off" id="searchinput" />
                <div id="searchresults">
                    &nbsp;
                </div>
            </div>
        </form>
	</div>

	<div id="bd">
		<div id="yui-main">
			<div class="yui-b">
            <form action="#" name="yui-classopts-form" method="get" id="yui-classopts-form">
                <fieldset>
                    <legend>Filters</legend>
                <span class="classopts"><input type="checkbox" name="show_private" id="show_private" /> <label for="show_private">Show Private</label></span>
                <span class="classopts"><input type="checkbox" name="show_protected" id="show_protected" /> <label for="show_protected">Show Protected</label></span>
                <span class="classopts"><input type="checkbox" name="show_deprecated" id="show_deprecated" /> <label for="show_deprecated">Show Deprecated</label></span>
                </fieldset>
            </form>

                    <div id="srcout">
                        <style>
                            #doc3 .classopts { display:none; }
                        </style>
<div class="highlight" ><pre><span class="c">/**</span>
<span class="c"> * The selector module provides helper methods allowing CSS2 Selectors to be used with DOM elements.</span>
<span class="c"> * @module dom</span>
<span class="c"> * @submodule selector-css2</span>
<span class="c"> * @for Selector</span>
<span class="c"> */</span>

<span class="c">/**</span>
<span class="c"> * Provides helper methods for collecting and filtering DOM elements.</span>
<span class="c"> */</span>

<span class="k">var</span> <span class="nx">PARENT_NODE</span> <span class="o">=</span> <span class="s1">&#39;parentNode&#39;</span><span class="o">,</span>
    <span class="nx">TAG_NAME</span> <span class="o">=</span> <span class="s1">&#39;tagName&#39;</span><span class="o">,</span>
    <span class="nx">ATTRIBUTES</span> <span class="o">=</span> <span class="s1">&#39;attributes&#39;</span><span class="o">,</span>
    <span class="nx">COMBINATOR</span> <span class="o">=</span> <span class="s1">&#39;combinator&#39;</span><span class="o">,</span>
    <span class="nx">PSEUDOS</span> <span class="o">=</span> <span class="s1">&#39;pseudos&#39;</span><span class="o">,</span>
    <span class="nx">PREVIOUS</span> <span class="o">=</span> <span class="s1">&#39;previous&#39;</span><span class="o">,</span>
    <span class="nx">PREVIOUS_SIBLING</span> <span class="o">=</span> <span class="s1">&#39;previousSibling&#39;</span><span class="o">,</span>

    <span class="nx">_childCache</span> <span class="o">=</span> <span class="o">[],</span> <span class="c">// cache to cleanup expando node.children</span>
<span class="c"></span>
    <span class="nx">Selector</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Selector</span><span class="o">,</span>

    <span class="nx">SelectorCSS2</span> <span class="o">=</span> <span class="o">{</span>
        <span class="nx">SORT_RESULTS</span><span class="o">:</span> <span class="kc">true</span><span class="o">,</span>
        <span class="nx">_children</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">node</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">node</span><span class="o">.</span><span class="nx">children</span><span class="o">,</span>
                <span class="nx">i</span><span class="o">,</span> <span class="nx">n</span><span class="o">;</span>

            <span class="k">if</span> <span class="o">(!</span><span class="nx">ret</span> <span class="o">&amp;&amp;</span> <span class="nx">node</span><span class="o">[</span><span class="nx">TAG_NAME</span><span class="o">])</span> <span class="o">{</span> <span class="c">// only HTMLElements have children</span>
<span class="c"></span>                <span class="nx">ret</span> <span class="o">=</span> <span class="o">[];</span>
                <span class="k">for</span> <span class="o">(</span><span class="nx">i</span> <span class="o">=</span> <span class="m">0</span><span class="o">,</span> <span class="nx">n</span><span class="o">;</span> <span class="nx">n</span> <span class="o">=</span> <span class="nx">node</span><span class="o">.</span><span class="nx">childNodes</span><span class="o">[</span><span class="nx">i</span><span class="o">++];)</span> <span class="o">{</span>
                    <span class="k">if</span> <span class="o">(</span><span class="nx">n</span><span class="o">.</span><span class="nx">tagName</span><span class="o">)</span> <span class="o">{</span>
                        <span class="nx">ret</span><span class="o">[</span><span class="nx">ret</span><span class="o">.</span><span class="nx">length</span><span class="o">]</span> <span class="o">=</span> <span class="nx">n</span><span class="o">;</span>
                    <span class="o">}</span>
                <span class="o">}</span>
                <span class="nx">_childCache</span><span class="o">[</span><span class="nx">_childCache</span><span class="o">.</span><span class="nx">length</span><span class="o">]</span> <span class="o">=</span> <span class="nx">node</span><span class="o">;</span>
                <span class="nx">node</span><span class="o">.</span><span class="nx">children</span> <span class="o">=</span> <span class="nx">ret</span><span class="o">;</span>
            <span class="o">}</span>

            <span class="k">return</span> <span class="nx">ret</span> <span class="o">||</span> <span class="o">[];</span>
        <span class="o">},</span>

        <span class="nx">_regexCache</span><span class="o">:</span> <span class="o">{},</span>

        <span class="nx">_re</span><span class="o">:</span> <span class="o">{</span>
            <span class="nx">attr</span><span class="o">:</span> <span class="sr">/(\[.*\])/g</span><span class="o">,</span>
            <span class="nx">urls</span><span class="o">:</span> <span class="sr">/^(?:href|src)/</span>
        <span class="o">},</span>

        <span class="c">/**</span>
<span class="c">         * Mapping of shorthand tokens to corresponding attribute selector </span>
<span class="c">         * @property shorthand</span>
<span class="c">         * @type object</span>
<span class="c">         */</span>
        <span class="nx">shorthand</span><span class="o">:</span> <span class="o">{</span>
            <span class="s1">&#39;\\#(-?[_a-z]+[-\\w]*)&#39;</span><span class="o">:</span> <span class="s1">&#39;[id=$1]&#39;</span><span class="o">,</span>
            <span class="s1">&#39;\\.(-?[_a-z]+[-\\w]*)&#39;</span><span class="o">:</span> <span class="s1">&#39;[className~=$1]&#39;</span>
        <span class="o">},</span>

        <span class="c">/**</span>
<span class="c">         * List of operators and corresponding boolean functions. </span>
<span class="c">         * These functions are passed the attribute and the current node&#39;s value of the attribute.</span>
<span class="c">         * @property operators</span>
<span class="c">         * @type object</span>
<span class="c">         */</span>
        <span class="nx">operators</span><span class="o">:</span> <span class="o">{</span>
            <span class="s1">&#39;&#39;</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">node</span><span class="o">,</span> <span class="nx">m</span><span class="o">)</span> <span class="o">{</span> <span class="k">return</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">DOM</span><span class="o">.</span><span class="nx">getAttribute</span><span class="o">(</span><span class="nx">node</span><span class="o">,</span> <span class="nx">m</span><span class="o">[</span><span class="m">0</span><span class="o">])</span> <span class="o">!==</span> <span class="s1">&#39;&#39;</span><span class="o">;</span> <span class="o">},</span> <span class="c">// Just test for existence of attribute</span>
<span class="c"></span>            <span class="c">//&#39;&#39;: &#39;.+&#39;,</span>
<span class="c"></span>            <span class="s1">&#39;=&#39;</span><span class="o">:</span> <span class="s1">&#39;^{val}$&#39;</span><span class="o">,</span> <span class="c">// equality</span>
<span class="c"></span>            <span class="s1">&#39;~=&#39;</span><span class="o">:</span> <span class="s1">&#39;(?:^|\\s+){val}(?:\\s+|$)&#39;</span><span class="o">,</span> <span class="c">// space-delimited</span>
<span class="c"></span>            <span class="s1">&#39;|=&#39;</span><span class="o">:</span> <span class="s1">&#39;^{val}-?&#39;</span> <span class="c">// optional hyphen-delimited</span>
<span class="c"></span>        <span class="o">},</span>

        <span class="nx">pseudos</span><span class="o">:</span> <span class="o">{</span>
           <span class="s1">&#39;first-child&#39;</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">node</span><span class="o">)</span> <span class="o">{</span> 
                <span class="k">return</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Selector</span><span class="o">.</span><span class="nx">_children</span><span class="o">(</span><span class="nx">node</span><span class="o">[</span><span class="nx">PARENT_NODE</span><span class="o">])[</span><span class="m">0</span><span class="o">]</span> <span class="o">===</span> <span class="nx">node</span><span class="o">;</span> 
            <span class="o">}</span> 
        <span class="o">},</span>

        <span class="nx">_brute</span><span class="o">:</span> <span class="o">{</span>
            <span class="c">/**</span>
<span class="c">             * Retrieves a set of nodes based on a given CSS selector. </span>
<span class="c">             * @method query</span>
<span class="c">             *</span>
<span class="c">             * @param {string} selector The CSS Selector to test the node against.</span>
<span class="c">             * @param {HTMLElement} root optional An HTMLElement to start the query from. Defaults to Y.config.doc</span>
<span class="c">             * @param {Boolean} firstOnly optional Whether or not to return only the first match.</span>
<span class="c">             * @return {Array} An array of nodes that match the given selector.</span>
<span class="c">             * @static</span>
<span class="c">             */</span>
            <span class="nx">query</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">selector</span><span class="o">,</span> <span class="nx">root</span><span class="o">,</span> <span class="nx">firstOnly</span><span class="o">)</span> <span class="o">{</span>
                <span class="k">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="o">[];</span>
                <span class="k">if</span> <span class="o">(</span><span class="nx">selector</span><span class="o">)</span> <span class="o">{</span>
                    <span class="nx">ret</span> <span class="o">=</span> <span class="nx">Selector</span><span class="o">.</span><span class="nx">_query</span><span class="o">(</span><span class="nx">selector</span><span class="o">,</span> <span class="nx">root</span><span class="o">,</span> <span class="nx">firstOnly</span><span class="o">);</span>
                <span class="o">}</span>

                <span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">&#39;query: &#39;</span> <span class="o">+</span> <span class="nx">selector</span> <span class="o">+</span> <span class="s1">&#39; returning: &#39;</span> <span class="o">+</span> <span class="nx">ret</span><span class="o">.</span><span class="nx">length</span><span class="o">,</span> <span class="s1">&#39;info&#39;</span><span class="o">,</span> <span class="s1">&#39;Selector&#39;</span><span class="o">);</span>
                <span class="nx">Selector</span><span class="o">.</span><span class="nx">_cleanup</span><span class="o">();</span>
                <span class="k">return</span> <span class="o">(</span><span class="nx">firstOnly</span><span class="o">)</span> <span class="o">?</span> <span class="o">(</span><span class="nx">ret</span><span class="o">[</span><span class="m">0</span><span class="o">]</span> <span class="o">||</span> <span class="kc">null</span><span class="o">)</span> <span class="o">:</span> <span class="nx">ret</span><span class="o">;</span>
            <span class="o">}</span>

        <span class="o">},</span>

        <span class="c">// TODO: make extensible? events?</span>
<span class="c"></span>        <span class="nx">_cleanup</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
            <span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="m">0</span><span class="o">,</span> <span class="nx">node</span><span class="o">;</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">_childCache</span><span class="o">[</span><span class="nx">i</span><span class="o">++];)</span> <span class="o">{</span>
                <span class="nx">delete</span> <span class="nx">node</span><span class="o">.</span><span class="nx">children</span><span class="o">;</span>
            <span class="o">}</span>

            <span class="nx">_childCache</span> <span class="o">=</span> <span class="o">[];</span>
        <span class="o">},</span>

        <span class="nx">_query</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">selector</span><span class="o">,</span> <span class="nx">root</span><span class="o">,</span> <span class="nx">firstOnly</span><span class="o">,</span> <span class="nx">deDupe</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="o">[],</span>
                <span class="nx">groups</span> <span class="o">=</span> <span class="nx">selector</span><span class="o">.</span><span class="nx">split</span><span class="o">(</span><span class="s1">&#39;,&#39;</span><span class="o">),</span> <span class="c">// TODO: handle comma in attribute/pseudo</span>
<span class="c"></span>                <span class="nx">nodes</span> <span class="o">=</span> <span class="o">[],</span>
                <span class="nx">tokens</span><span class="o">,</span>
                <span class="nx">token</span><span class="o">,</span>
                <span class="nx">i</span><span class="o">,</span> <span class="nx">len</span><span class="o">;</span>

            <span class="k">if</span> <span class="o">(</span><span class="nx">groups</span><span class="o">.</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="m">1</span><span class="o">)</span> <span class="o">{</span>
                <span class="k">for</span> <span class="o">(</span><span class="nx">i</span> <span class="o">=</span> <span class="m">0</span><span class="o">,</span> <span class="nx">len</span> <span class="o">=</span> <span class="nx">groups</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">len</span><span class="o">;</span> <span class="o">++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
                    <span class="nx">ret</span> <span class="o">=</span> <span class="nx">ret</span><span class="o">.</span><span class="nx">concat</span><span class="o">(</span><span class="nx">arguments</span><span class="o">.</span><span class="nx">callee</span><span class="o">(</span><span class="nx">groups</span><span class="o">[</span><span class="nx">i</span><span class="o">],</span>
                            <span class="nx">root</span><span class="o">,</span> <span class="nx">firstOnly</span><span class="o">,</span> <span class="kc">true</span><span class="o">));</span> 
                <span class="o">}</span>

                <span class="nx">ret</span> <span class="o">=</span> <span class="nx">Selector</span><span class="o">.</span><span class="nx">SORT_RESULTS</span> <span class="o">?</span> <span class="nx">Selector</span><span class="o">.</span><span class="nx">_sort</span><span class="o">(</span><span class="nx">ret</span><span class="o">)</span> <span class="o">:</span> <span class="nx">ret</span><span class="o">;</span>
                <span class="nx">Selector</span><span class="o">.</span><span class="nx">_clearFoundCache</span><span class="o">();</span>
            <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
                <span class="nx">root</span> <span class="o">=</span> <span class="nx">root</span> <span class="o">||</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">config</span><span class="o">.</span><span class="nx">doc</span><span class="o">;</span>

                <span class="k">if</span> <span class="o">(</span><span class="nx">root</span><span class="o">.</span><span class="nx">nodeType</span> <span class="o">!==</span> <span class="m">9</span><span class="o">)</span> <span class="o">{</span> <span class="c">// enforce element scope</span>
<span class="c"></span>                    <span class="k">if</span> <span class="o">(!</span><span class="nx">root</span><span class="o">.</span><span class="nx">id</span><span class="o">)</span> <span class="o">{</span>
                        <span class="nx">root</span><span class="o">.</span><span class="nx">id</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">guid</span><span class="o">();</span>
                    <span class="o">}</span>
                    <span class="c">// fast-path ID when possible</span>
<span class="c"></span>                    <span class="k">if</span> <span class="o">(</span><span class="nx">root</span><span class="o">.</span><span class="nx">ownerDocument</span><span class="o">.</span><span class="nx">getElementById</span><span class="o">(</span><span class="nx">root</span><span class="o">.</span><span class="nx">id</span><span class="o">))</span> <span class="o">{</span>
                        <span class="nx">selector</span> <span class="o">=</span> <span class="s1">&#39;#&#39;</span> <span class="o">+</span> <span class="nx">root</span><span class="o">.</span><span class="nx">id</span> <span class="o">+</span> <span class="s1">&#39; &#39;</span> <span class="o">+</span> <span class="nx">selector</span><span class="o">;</span>
                        <span class="nx">root</span> <span class="o">=</span> <span class="nx">root</span><span class="o">.</span><span class="nx">ownerDocument</span><span class="o">;</span>

                    <span class="o">}</span>
                <span class="o">}</span>

                <span class="nx">tokens</span> <span class="o">=</span> <span class="nx">Selector</span><span class="o">.</span><span class="nx">_tokenize</span><span class="o">(</span><span class="nx">selector</span><span class="o">,</span> <span class="nx">root</span><span class="o">);</span>
                <span class="nx">token</span> <span class="o">=</span> <span class="nx">tokens</span><span class="o">.</span><span class="nx">pop</span><span class="o">();</span>

                <span class="k">if</span> <span class="o">(</span><span class="nx">token</span><span class="o">)</span> <span class="o">{</span>
                    <span class="k">if</span> <span class="o">(</span><span class="nx">deDupe</span><span class="o">)</span> <span class="o">{</span>
                        <span class="nx">token</span><span class="o">.</span><span class="nx">deDupe</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span> <span class="c">// TODO: better approach?</span>
<span class="c"></span>                    <span class="o">}</span>
                    <span class="k">if</span> <span class="o">(</span><span class="nx">tokens</span><span class="o">[</span><span class="m">0</span><span class="o">]</span> <span class="o">&amp;&amp;</span> <span class="nx">tokens</span><span class="o">[</span><span class="m">0</span><span class="o">].</span><span class="nx">id</span> <span class="o">&amp;&amp;</span> <span class="nx">root</span><span class="o">.</span><span class="nx">nodeType</span> <span class="o">===</span> <span class="m">9</span> <span class="o">&amp;&amp;</span> <span class="nx">root</span><span class="o">.</span><span class="nx">getElementById</span><span class="o">(</span><span class="nx">tokens</span><span class="o">[</span><span class="m">0</span><span class="o">].</span><span class="nx">id</span><span class="o">))</span> <span class="o">{</span>
                        <span class="nx">root</span> <span class="o">=</span> <span class="nx">root</span><span class="o">.</span><span class="nx">getElementById</span><span class="o">(</span><span class="nx">tokens</span><span class="o">[</span><span class="m">0</span><span class="o">].</span><span class="nx">id</span><span class="o">);</span>
                    <span class="o">}</span>

                    <span class="c">// TODO: no prefilter for off-dom id</span>
<span class="c"></span>                    <span class="k">if</span> <span class="o">(</span><span class="nx">root</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">nodes</span><span class="o">.</span><span class="nx">length</span> <span class="o">&amp;&amp;</span> <span class="nx">token</span><span class="o">.</span><span class="nx">prefilter</span><span class="o">)</span> <span class="o">{</span>
                        <span class="nx">nodes</span> <span class="o">=</span> <span class="nx">token</span><span class="o">.</span><span class="nx">prefilter</span><span class="o">(</span><span class="nx">root</span><span class="o">,</span> <span class="nx">token</span><span class="o">);</span>
                    <span class="o">}</span>

                    <span class="k">if</span> <span class="o">(</span><span class="nx">nodes</span><span class="o">.</span><span class="nx">length</span><span class="o">)</span> <span class="o">{</span>
                        <span class="k">if</span> <span class="o">(</span><span class="nx">firstOnly</span><span class="o">)</span> <span class="o">{</span>
                            <span class="nx">Y</span><span class="o">.</span><span class="nb">Array</span><span class="o">.</span><span class="nx">some</span><span class="o">(</span><span class="nx">nodes</span><span class="o">,</span> <span class="nx">Selector</span><span class="o">.</span><span class="nx">_testToken</span><span class="o">,</span> <span class="nx">token</span><span class="o">);</span>
                        <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
                            <span class="nx">Y</span><span class="o">.</span><span class="nb">Array</span><span class="o">.</span><span class="nx">each</span><span class="o">(</span><span class="nx">nodes</span><span class="o">,</span> <span class="nx">Selector</span><span class="o">.</span><span class="nx">_testToken</span><span class="o">,</span> <span class="nx">token</span><span class="o">);</span>
                        <span class="o">}</span>
                    <span class="o">}</span>
                    <span class="nx">ret</span> <span class="o">=</span> <span class="nx">token</span><span class="o">.</span><span class="nx">result</span><span class="o">;</span>
                <span class="o">}</span>
            <span class="o">}</span>

            <span class="k">return</span> <span class="nx">ret</span><span class="o">;</span>
        <span class="o">},</span>

        <span class="nx">_testToken</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">node</span><span class="o">,</span> <span class="nx">index</span><span class="o">,</span> <span class="nx">nodes</span><span class="o">,</span> <span class="nx">token</span><span class="o">)</span> <span class="o">{</span>
            <span class="nx">token</span> <span class="o">=</span> <span class="nx">token</span> <span class="o">||</span> <span class="k">this</span><span class="o">;</span>
            <span class="k">var</span> <span class="nx">tag</span> <span class="o">=</span> <span class="nx">token</span><span class="o">.</span><span class="nx">tag</span><span class="o">,</span>
                <span class="nx">previous</span> <span class="o">=</span> <span class="nx">token</span><span class="o">[</span><span class="nx">PREVIOUS</span><span class="o">],</span>
                <span class="nx">result</span> <span class="o">=</span> <span class="nx">token</span><span class="o">.</span><span class="nx">result</span><span class="o">,</span>
                <span class="nx">i</span> <span class="o">=</span> <span class="m">0</span><span class="o">,</span>
                <span class="nx">nextTest</span> <span class="o">=</span> <span class="nx">previous</span> <span class="o">&amp;&amp;</span> <span class="nx">previous</span><span class="o">[</span><span class="nx">COMBINATOR</span><span class="o">]</span> <span class="o">?</span>
                        <span class="nx">Selector</span><span class="o">.</span><span class="nx">combinators</span><span class="o">[</span><span class="nx">previous</span><span class="o">[</span><span class="nx">COMBINATOR</span><span class="o">]]</span> <span class="o">:</span>
                        <span class="kc">null</span><span class="o">,</span>
                <span class="nx">test</span><span class="o">,</span>
                <span class="nx">attr</span><span class="o">;</span>

            <span class="k">if</span> <span class="o">(</span><span class="c">//node[TAG_NAME] &amp;&amp; // tagName limits to HTMLElements</span>
<span class="c"></span>                    <span class="o">(</span><span class="nx">tag</span> <span class="o">===</span> <span class="s1">&#39;*&#39;</span> <span class="o">||</span> <span class="nx">tag</span> <span class="o">===</span> <span class="nx">node</span><span class="o">[</span><span class="nx">TAG_NAME</span><span class="o">])</span> <span class="o">&amp;&amp;</span>
                    <span class="o">!(</span><span class="nx">token</span><span class="o">.</span><span class="nx">last</span> <span class="o">&amp;&amp;</span> <span class="nx">node</span><span class="o">.</span><span class="nx">_found</span><span class="o">)</span> <span class="o">)</span> <span class="o">{</span>
                <span class="k">while</span> <span class="o">((</span><span class="nx">attr</span> <span class="o">=</span> <span class="nx">token</span><span class="o">.</span><span class="nx">tests</span><span class="o">[</span><span class="nx">i</span><span class="o">]))</span> <span class="o">{</span>
                    <span class="nx">i</span><span class="o">++;</span>
                    <span class="nx">test</span> <span class="o">=</span> <span class="nx">attr</span><span class="o">.</span><span class="nx">test</span><span class="o">;</span>
                    <span class="k">if</span> <span class="o">(</span><span class="nx">test</span><span class="o">.</span><span class="nx">test</span><span class="o">)</span> <span class="o">{</span>
                        <span class="k">if</span> <span class="o">(!</span><span class="nx">test</span><span class="o">.</span><span class="nx">test</span><span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">DOM</span><span class="o">.</span><span class="nx">getAttribute</span><span class="o">(</span><span class="nx">node</span><span class="o">,</span> <span class="nx">attr</span><span class="o">.</span><span class="nx">name</span><span class="o">)))</span> <span class="o">{</span>
                            <span class="k">return</span> <span class="kc">false</span><span class="o">;</span>
                        <span class="o">}</span>
                    <span class="o">}</span> <span class="k">else</span> <span class="k">if</span> <span class="o">(!</span><span class="nx">test</span><span class="o">(</span><span class="nx">node</span><span class="o">,</span> <span class="nx">attr</span><span class="o">.</span><span class="nx">match</span><span class="o">))</span> <span class="o">{</span>
                        <span class="k">return</span> <span class="kc">false</span><span class="o">;</span>
                    <span class="o">}</span>
                <span class="o">}</span>

                <span class="k">if</span> <span class="o">(</span><span class="nx">nextTest</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">nextTest</span><span class="o">(</span><span class="nx">node</span><span class="o">,</span> <span class="nx">token</span><span class="o">))</span> <span class="o">{</span>
                    <span class="k">return</span> <span class="kc">false</span><span class="o">;</span>
                <span class="o">}</span>

                <span class="k">if</span> <span class="o">(</span><span class="nx">token</span><span class="o">.</span><span class="nx">root</span> <span class="o">&amp;&amp;</span> <span class="nx">token</span><span class="o">.</span><span class="nx">root</span><span class="o">.</span><span class="nx">nodeType</span> <span class="o">!==</span> <span class="m">9</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">Y</span><span class="o">.</span><span class="nx">DOM</span><span class="o">.</span><span class="nx">contains</span><span class="o">(</span><span class="nx">token</span><span class="o">.</span><span class="nx">root</span><span class="o">,</span> <span class="nx">node</span><span class="o">))</span> <span class="o">{</span>
                    <span class="k">return</span> <span class="kc">false</span><span class="o">;</span>
                <span class="o">}</span>

                <span class="nx">result</span><span class="o">[</span><span class="nx">result</span><span class="o">.</span><span class="nx">length</span><span class="o">]</span> <span class="o">=</span> <span class="nx">node</span><span class="o">;</span>
                <span class="k">if</span> <span class="o">(</span><span class="nx">token</span><span class="o">.</span><span class="nx">deDupe</span> <span class="o">&amp;&amp;</span> <span class="nx">token</span><span class="o">.</span><span class="nx">last</span><span class="o">)</span> <span class="o">{</span>
                    <span class="nx">node</span><span class="o">.</span><span class="nx">_found</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
                    <span class="nx">Selector</span><span class="o">.</span><span class="nx">_foundCache</span><span class="o">.</span><span class="nx">push</span><span class="o">(</span><span class="nx">node</span><span class="o">);</span>
                <span class="o">}</span>
                <span class="k">return</span> <span class="kc">true</span><span class="o">;</span>
            <span class="o">}</span>
            <span class="k">return</span> <span class="kc">false</span><span class="o">;</span>
        <span class="o">},</span>


        <span class="nx">_getRegExp</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">str</span><span class="o">,</span> <span class="nx">flags</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">var</span> <span class="nx">regexCache</span> <span class="o">=</span> <span class="nx">Selector</span><span class="o">.</span><span class="nx">_regexCache</span><span class="o">;</span>
            <span class="nx">flags</span> <span class="o">=</span> <span class="nx">flags</span> <span class="o">||</span> <span class="s1">&#39;&#39;</span><span class="o">;</span>
            <span class="k">if</span> <span class="o">(!</span><span class="nx">regexCache</span><span class="o">[</span><span class="nx">str</span> <span class="o">+</span> <span class="nx">flags</span><span class="o">])</span> <span class="o">{</span>
                <span class="nx">regexCache</span><span class="o">[</span><span class="nx">str</span> <span class="o">+</span> <span class="nx">flags</span><span class="o">]</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">RegExp</span><span class="o">(</span><span class="nx">str</span><span class="o">,</span> <span class="nx">flags</span><span class="o">);</span>
            <span class="o">}</span>
            <span class="k">return</span> <span class="nx">regexCache</span><span class="o">[</span><span class="nx">str</span> <span class="o">+</span> <span class="nx">flags</span><span class="o">];</span>
        <span class="o">},</span>

        <span class="nx">combinators</span><span class="o">:</span> <span class="o">{</span>
            <span class="s1">&#39; &#39;</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">node</span><span class="o">,</span> <span class="nx">token</span><span class="o">)</span> <span class="o">{</span>
                <span class="k">var</span> <span class="nx">test</span> <span class="o">=</span> <span class="nx">Selector</span><span class="o">.</span><span class="nx">_testToken</span><span class="o">,</span>
                    <span class="nx">previous</span> <span class="o">=</span> <span class="nx">token</span><span class="o">[</span><span class="nx">PREVIOUS</span><span class="o">];</span>
                <span class="k">while</span> <span class="o">(</span> <span class="o">(</span><span class="nx">node</span> <span class="o">=</span> <span class="nx">node</span><span class="o">[</span><span class="nx">PARENT_NODE</span><span class="o">])</span> <span class="o">)</span> <span class="o">{</span>
                    <span class="k">if</span> <span class="o">(</span><span class="nx">test</span><span class="o">(</span><span class="nx">node</span><span class="o">,</span> <span class="kc">null</span><span class="o">,</span> <span class="kc">null</span><span class="o">,</span> <span class="nx">previous</span><span class="o">))</span> <span class="o">{</span>
                        <span class="k">return</span> <span class="kc">true</span><span class="o">;</span>
                    <span class="o">}</span>
                <span class="o">}</span>  
                <span class="k">return</span> <span class="kc">false</span><span class="o">;</span>
            <span class="o">},</span>

            <span class="s1">&#39;&gt;&#39;</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">node</span><span class="o">,</span> <span class="nx">token</span><span class="o">)</span> <span class="o">{</span>
                <span class="k">return</span> <span class="nx">Selector</span><span class="o">.</span><span class="nx">_testToken</span><span class="o">(</span><span class="nx">node</span><span class="o">[</span><span class="nx">PARENT_NODE</span><span class="o">],</span> <span class="kc">null</span><span class="o">,</span> <span class="kc">null</span><span class="o">,</span> <span class="nx">token</span><span class="o">[</span><span class="nx">PREVIOUS</span><span class="o">]);</span>
            <span class="o">},</span>


            <span class="s1">&#39;+&#39;</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">node</span><span class="o">,</span> <span class="nx">token</span><span class="o">)</span> <span class="o">{</span>
                <span class="k">var</span> <span class="nx">sib</span> <span class="o">=</span> <span class="nx">node</span><span class="o">[</span><span class="nx">PREVIOUS_SIBLING</span><span class="o">];</span>
                <span class="k">while</span> <span class="o">(</span><span class="nx">sib</span> <span class="o">&amp;&amp;</span> <span class="nx">sib</span><span class="o">.</span><span class="nx">nodeType</span> <span class="o">!==</span> <span class="m">1</span><span class="o">)</span> <span class="o">{</span>
                    <span class="nx">sib</span> <span class="o">=</span> <span class="nx">sib</span><span class="o">[</span><span class="nx">PREVIOUS_SIBLING</span><span class="o">];</span>
                <span class="o">}</span>

                <span class="k">if</span> <span class="o">(</span><span class="nx">sib</span> <span class="o">&amp;&amp;</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Selector</span><span class="o">.</span><span class="nx">_testToken</span><span class="o">(</span><span class="nx">sib</span><span class="o">,</span> <span class="kc">null</span><span class="o">,</span> <span class="kc">null</span><span class="o">,</span> <span class="nx">token</span><span class="o">[</span><span class="nx">PREVIOUS</span><span class="o">]))</span> <span class="o">{</span>
                    <span class="k">return</span> <span class="kc">true</span><span class="o">;</span> 
                <span class="o">}</span>
                <span class="k">return</span> <span class="kc">false</span><span class="o">;</span>
            <span class="o">}</span>

        <span class="o">},</span>

        <span class="nx">_parsers</span><span class="o">:</span> <span class="o">[</span>
            <span class="o">{</span>
                <span class="nx">name</span><span class="o">:</span> <span class="nx">TAG_NAME</span><span class="o">,</span>
                <span class="nx">re</span><span class="o">:</span> <span class="sr">/^((?:-?[_a-z]+[\w-]*)|\*)/i</span><span class="o">,</span>
                <span class="nx">fn</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">token</span><span class="o">,</span> <span class="nx">match</span><span class="o">)</span> <span class="o">{</span>
                    <span class="nx">token</span><span class="o">.</span><span class="nx">tag</span> <span class="o">=</span> <span class="nx">match</span><span class="o">[</span><span class="m">1</span><span class="o">].</span><span class="nx">toUpperCase</span><span class="o">();</span>
                    <span class="nx">token</span><span class="o">.</span><span class="nx">prefilter</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">root</span><span class="o">)</span> <span class="o">{</span>
                        <span class="k">return</span> <span class="nx">root</span><span class="o">.</span><span class="nx">getElementsByTagName</span><span class="o">(</span><span class="nx">token</span><span class="o">.</span><span class="nx">tag</span><span class="o">);</span>
                    <span class="o">};</span>
                    <span class="k">return</span> <span class="kc">true</span><span class="o">;</span>
                <span class="o">}</span>
            <span class="o">},</span>
            <span class="o">{</span>
                <span class="nx">name</span><span class="o">:</span> <span class="nx">ATTRIBUTES</span><span class="o">,</span>
                <span class="nx">re</span><span class="o">:</span> <span class="sr">/^\[([a-z]+\w*)+([~\|\^\$\*!=]=?)?[&#39;&quot;]?([^\]]*?)[&#39;&quot;]?\]/i</span><span class="o">,</span>
                <span class="nx">fn</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">token</span><span class="o">,</span> <span class="nx">match</span><span class="o">)</span> <span class="o">{</span>
                    <span class="k">var</span> <span class="nx">val</span> <span class="o">=</span> <span class="nx">match</span><span class="o">[</span><span class="m">3</span><span class="o">],</span>
                        <span class="nx">operator</span> <span class="o">=</span> <span class="o">!(</span><span class="nx">match</span><span class="o">[</span><span class="m">2</span><span class="o">]</span> <span class="o">&amp;&amp;</span> <span class="nx">val</span><span class="o">)</span> <span class="o">?</span> <span class="s1">&#39;&#39;</span> <span class="o">:</span> <span class="nx">match</span><span class="o">[</span><span class="m">2</span><span class="o">],</span>
                        <span class="nx">test</span> <span class="o">=</span> <span class="nx">Selector</span><span class="o">.</span><span class="nx">operators</span><span class="o">[</span><span class="nx">operator</span><span class="o">];</span>

                    <span class="c">// might be a function</span>
<span class="c"></span>                    <span class="k">if</span> <span class="o">(</span><span class="k">typeof</span> <span class="nx">test</span> <span class="o">===</span> <span class="s1">&#39;string&#39;</span><span class="o">)</span> <span class="o">{</span>
                        <span class="nx">test</span> <span class="o">=</span> <span class="nx">Selector</span><span class="o">.</span><span class="nx">_getRegExp</span><span class="o">(</span><span class="nx">test</span><span class="o">.</span><span class="nx">replace</span><span class="o">(</span><span class="s1">&#39;{val}&#39;</span><span class="o">,</span> <span class="nx">val</span><span class="o">));</span>
                    <span class="o">}</span>
                    
                    <span class="k">if</span> <span class="o">(</span><span class="nx">match</span><span class="o">[</span><span class="m">1</span><span class="o">]</span> <span class="o">===</span> <span class="s1">&#39;id&#39;</span> <span class="o">&amp;&amp;</span> <span class="nx">val</span><span class="o">)</span> <span class="o">{</span> <span class="c">// store ID for fast-path match</span>
<span class="c"></span>                        <span class="nx">token</span><span class="o">.</span><span class="nx">id</span> <span class="o">=</span> <span class="nx">val</span><span class="o">;</span>
                        <span class="nx">token</span><span class="o">.</span><span class="nx">prefilter</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">root</span><span class="o">)</span> <span class="o">{</span>
                            <span class="k">var</span> <span class="nx">doc</span> <span class="o">=</span> <span class="nx">root</span><span class="o">.</span><span class="nx">nodeType</span> <span class="o">===</span> <span class="m">9</span> <span class="o">?</span> <span class="nx">root</span> <span class="o">:</span> <span class="nx">root</span><span class="o">.</span><span class="nx">ownerDocument</span><span class="o">,</span>
                                <span class="nx">node</span> <span class="o">=</span> <span class="nx">doc</span><span class="o">.</span><span class="nx">getElementById</span><span class="o">(</span><span class="nx">val</span><span class="o">);</span>
                            
                            <span class="k">return</span> <span class="nx">node</span> <span class="o">?</span> <span class="o">[</span><span class="nx">node</span><span class="o">]</span> <span class="o">:</span> <span class="o">[];</span>
                        <span class="o">};</span>
                    <span class="o">}</span> <span class="k">else</span> <span class="k">if</span> <span class="o">(</span><span class="nb">document</span><span class="o">.</span><span class="nx">documentElement</span><span class="o">.</span><span class="nx">getElementsByClassName</span> <span class="o">&amp;&amp;</span> 
                            <span class="nx">match</span><span class="o">[</span><span class="m">1</span><span class="o">].</span><span class="nx">indexOf</span><span class="o">(</span><span class="s1">&#39;class&#39;</span><span class="o">)</span> <span class="o">===</span> <span class="m">0</span><span class="o">)</span> <span class="o">{</span>
                        <span class="k">if</span> <span class="o">(!</span><span class="nx">token</span><span class="o">.</span><span class="nx">prefilter</span><span class="o">)</span> <span class="o">{</span>
                            <span class="nx">token</span><span class="o">.</span><span class="nx">prefilter</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">root</span><span class="o">)</span> <span class="o">{</span>
                                <span class="k">return</span> <span class="nx">root</span><span class="o">.</span><span class="nx">getElementsByClassName</span><span class="o">(</span><span class="nx">val</span><span class="o">);</span>
                            <span class="o">};</span>
                            <span class="nx">test</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span> <span class="c">// skip class test </span>
<span class="c"></span>                        <span class="o">}</span>
                    <span class="o">}</span>
                    <span class="k">return</span> <span class="nx">test</span><span class="o">;</span>

                <span class="o">}</span>

            <span class="o">},</span>
            <span class="o">{</span>
                <span class="nx">name</span><span class="o">:</span> <span class="nx">COMBINATOR</span><span class="o">,</span>
                <span class="nx">re</span><span class="o">:</span> <span class="sr">/^\s*([&gt;+~]|\s)\s*/</span><span class="o">,</span>
                <span class="nx">fn</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">token</span><span class="o">,</span> <span class="nx">match</span><span class="o">)</span> <span class="o">{</span>
                    <span class="nx">token</span><span class="o">[</span><span class="nx">COMBINATOR</span><span class="o">]</span> <span class="o">=</span> <span class="nx">match</span><span class="o">[</span><span class="m">1</span><span class="o">];</span>
                    <span class="k">return</span> <span class="o">!!</span> <span class="nx">Selector</span><span class="o">.</span><span class="nx">combinators</span><span class="o">[</span><span class="nx">token</span><span class="o">[</span><span class="nx">COMBINATOR</span><span class="o">]];</span>
                <span class="o">}</span>
            <span class="o">},</span>
            <span class="o">{</span>
                <span class="nx">name</span><span class="o">:</span> <span class="nx">PSEUDOS</span><span class="o">,</span>
                <span class="nx">re</span><span class="o">:</span> <span class="sr">/^:([\-\w]+)(?:\([&#39;&quot;]?(.+)[&#39;&quot;]?\))*/i</span><span class="o">,</span>
                <span class="nx">fn</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">token</span><span class="o">,</span> <span class="nx">match</span><span class="o">)</span> <span class="o">{</span>
                    <span class="k">return</span> <span class="nx">Selector</span><span class="o">[</span><span class="nx">PSEUDOS</span><span class="o">][</span><span class="nx">match</span><span class="o">[</span><span class="m">1</span><span class="o">]];</span>

                <span class="o">}</span>
            <span class="o">}</span>
            <span class="o">],</span>

        <span class="nx">_getToken</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">token</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">return</span> <span class="o">{</span>
                <span class="nx">previous</span><span class="o">:</span> <span class="nx">token</span><span class="o">,</span>
                <span class="nx">combinator</span><span class="o">:</span> <span class="s1">&#39; &#39;</span><span class="o">,</span>
                <span class="nx">tag</span><span class="o">:</span> <span class="s1">&#39;*&#39;</span><span class="o">,</span>
                <span class="nx">prefilter</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">root</span><span class="o">)</span> <span class="o">{</span>
                    <span class="k">return</span> <span class="nx">root</span><span class="o">.</span><span class="nx">getElementsByTagName</span><span class="o">(</span><span class="s1">&#39;*&#39;</span><span class="o">);</span>
                <span class="o">},</span>
                <span class="nx">tests</span><span class="o">:</span> <span class="o">[],</span>
                <span class="nx">result</span><span class="o">:</span> <span class="o">[]</span>
            <span class="o">};</span>
        <span class="o">},</span>

        <span class="c">/**</span>
<span class="c">            Break selector into token units per simple selector.</span>
<span class="c">            Combinator is attached to the previous token.</span>
<span class="c">         */</span>
        <span class="nx">_tokenize</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">selector</span><span class="o">,</span> <span class="nx">root</span><span class="o">)</span> <span class="o">{</span>
            <span class="nx">selector</span> <span class="o">=</span> <span class="nx">selector</span> <span class="o">||</span> <span class="s1">&#39;&#39;</span><span class="o">;</span>
            <span class="nx">selector</span> <span class="o">=</span> <span class="nx">Selector</span><span class="o">.</span><span class="nx">_replaceShorthand</span><span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">Lang</span><span class="o">.</span><span class="nx">trim</span><span class="o">(</span><span class="nx">selector</span><span class="o">));</span> 
            <span class="k">var</span> <span class="nx">token</span> <span class="o">=</span> <span class="nx">Selector</span><span class="o">.</span><span class="nx">_getToken</span><span class="o">(),</span>     <span class="c">// one token per simple selector (left selector holds combinator)</span>
<span class="c"></span>                <span class="nx">query</span> <span class="o">=</span> <span class="nx">selector</span><span class="o">,</span> <span class="c">// original query for debug report</span>
<span class="c"></span>                <span class="nx">tokens</span> <span class="o">=</span> <span class="o">[],</span>    <span class="c">// array of tokens</span>
<span class="c"></span>                <span class="nx">found</span> <span class="o">=</span> <span class="kc">false</span><span class="o">,</span>  <span class="c">// whether or not any matches were found this pass</span>
<span class="c"></span>                <span class="nx">test</span><span class="o">,</span>
                <span class="nx">match</span><span class="o">,</span>         <span class="c">// the regex match</span>
<span class="c"></span>                <span class="nx">i</span><span class="o">,</span> <span class="nx">parser</span><span class="o">;</span>

            <span class="c">/*</span>
<span class="c">                Search for selector patterns, store, and strip them from the selector string</span>
<span class="c">                until no patterns match (invalid selector) or we run out of chars.</span>
<span class="c"></span>
<span class="c">                Multiple attributes and pseudos are allowed, in any order.</span>
<span class="c">                for example:</span>
<span class="c">                    &#39;form:first-child[type=button]:not(button)[lang|=en]&#39;</span>
<span class="c">            */</span>
            <span class="nx">outer</span><span class="o">:</span>
            <span class="k">do</span> <span class="o">{</span>
                <span class="nx">found</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span> <span class="c">// reset after full pass</span>
<span class="c"></span>                <span class="k">for</span> <span class="o">(</span><span class="nx">i</span> <span class="o">=</span> <span class="m">0</span><span class="o">,</span> <span class="nx">parser</span><span class="o">;</span> <span class="nx">parser</span> <span class="o">=</span> <span class="nx">Selector</span><span class="o">.</span><span class="nx">_parsers</span><span class="o">[</span><span class="nx">i</span><span class="o">++];)</span> <span class="o">{</span>
                    <span class="k">if</span> <span class="o">(</span> <span class="o">(</span><span class="nx">match</span> <span class="o">=</span> <span class="nx">parser</span><span class="o">.</span><span class="nx">re</span><span class="o">.</span><span class="nx">exec</span><span class="o">(</span><span class="nx">selector</span><span class="o">))</span> <span class="o">)</span> <span class="o">{</span> <span class="c">// note assignment</span>
<span class="c"></span>                        <span class="nx">test</span> <span class="o">=</span> <span class="nx">parser</span><span class="o">.</span><span class="nx">fn</span><span class="o">(</span><span class="nx">token</span><span class="o">,</span> <span class="nx">match</span><span class="o">);</span>
                        <span class="k">if</span> <span class="o">(</span><span class="nx">test</span><span class="o">)</span> <span class="o">{</span>
                            <span class="k">if</span> <span class="o">(</span><span class="nx">test</span> <span class="o">!==</span> <span class="kc">true</span><span class="o">)</span> <span class="o">{</span> <span class="c">// auto-pass</span>
<span class="c"></span>                                <span class="nx">token</span><span class="o">.</span><span class="nx">tests</span><span class="o">.</span><span class="nx">push</span><span class="o">({</span>
                                    <span class="nx">name</span><span class="o">:</span> <span class="nx">match</span><span class="o">[</span><span class="m">1</span><span class="o">],</span>
                                    <span class="nx">test</span><span class="o">:</span> <span class="nx">test</span><span class="o">,</span>
                                    <span class="nx">match</span><span class="o">:</span> <span class="nx">match</span><span class="o">.</span><span class="nx">slice</span><span class="o">(</span><span class="m">1</span><span class="o">)</span>
                                <span class="o">});</span>
                            <span class="o">}</span>

                            <span class="nx">found</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
                            <span class="nx">selector</span> <span class="o">=</span> <span class="nx">selector</span><span class="o">.</span><span class="nx">replace</span><span class="o">(</span><span class="nx">match</span><span class="o">[</span><span class="m">0</span><span class="o">],</span> <span class="s1">&#39;&#39;</span><span class="o">);</span> <span class="c">// strip current match from selector</span>
<span class="c"></span>                            <span class="k">if</span> <span class="o">(!</span><span class="nx">selector</span><span class="o">.</span><span class="nx">length</span> <span class="o">||</span> <span class="nx">parser</span><span class="o">.</span><span class="nx">name</span> <span class="o">===</span> <span class="nx">COMBINATOR</span><span class="o">)</span> <span class="o">{</span>
                                <span class="nx">token</span><span class="o">.</span><span class="nx">root</span> <span class="o">=</span> <span class="nx">root</span><span class="o">;</span>
                                <span class="nx">tokens</span><span class="o">.</span><span class="nx">push</span><span class="o">(</span><span class="nx">token</span><span class="o">);</span>
                                <span class="nx">token</span> <span class="o">=</span> <span class="nx">Selector</span><span class="o">.</span><span class="nx">_getToken</span><span class="o">(</span><span class="nx">token</span><span class="o">);</span>
                            <span class="o">}</span>
                        <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
                            <span class="nx">found</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>
                            <span class="k">break</span> <span class="nx">outer</span><span class="o">;</span>
                        <span class="o">}</span>
                    <span class="o">}</span>
                <span class="o">}</span>
            <span class="o">}</span> <span class="k">while</span> <span class="o">(</span><span class="nx">found</span> <span class="o">&amp;&amp;</span> <span class="nx">selector</span><span class="o">.</span><span class="nx">length</span><span class="o">);</span>

            <span class="k">if</span> <span class="o">(!</span><span class="nx">found</span> <span class="o">||</span> <span class="nx">selector</span><span class="o">.</span><span class="nx">length</span><span class="o">)</span> <span class="o">{</span> <span class="c">// not fully parsed</span>
<span class="c"></span>                <span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">&#39;query: &#39;</span> <span class="o">+</span> <span class="nx">query</span> <span class="o">+</span> <span class="s1">&#39; contains unsupported token in: &#39;</span> <span class="o">+</span> <span class="nx">selector</span><span class="o">,</span> <span class="s1">&#39;warn&#39;</span><span class="o">,</span> <span class="s1">&#39;Selector&#39;</span><span class="o">);</span>
                <span class="nx">tokens</span> <span class="o">=</span> <span class="o">[];</span>
            <span class="o">}</span> <span class="k">else</span> <span class="k">if</span> <span class="o">(</span><span class="nx">tokens</span><span class="o">.</span><span class="nx">length</span><span class="o">)</span> <span class="o">{</span>
                <span class="nx">tokens</span><span class="o">[</span><span class="nx">tokens</span><span class="o">.</span><span class="nx">length</span> <span class="o">-</span> <span class="m">1</span><span class="o">].</span><span class="nx">last</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
            <span class="o">}</span>
            <span class="k">return</span> <span class="nx">tokens</span><span class="o">;</span>
        <span class="o">},</span>

        <span class="nx">_replaceShorthand</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">selector</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">var</span> <span class="nx">shorthand</span> <span class="o">=</span> <span class="nx">Selector</span><span class="o">.</span><span class="nx">shorthand</span><span class="o">,</span>
                <span class="nx">attrs</span> <span class="o">=</span> <span class="nx">selector</span><span class="o">.</span><span class="nx">match</span><span class="o">(</span><span class="nx">Selector</span><span class="o">.</span><span class="nx">_re</span><span class="o">.</span><span class="nx">attr</span><span class="o">),</span> <span class="c">// pull attributes to avoid false pos on &quot;.&quot; and &quot;#&quot;</span>
<span class="c"></span>                <span class="nx">re</span><span class="o">,</span> <span class="nx">i</span><span class="o">,</span> <span class="nx">len</span><span class="o">;</span>

            <span class="k">if</span> <span class="o">(</span><span class="nx">attrs</span><span class="o">)</span> <span class="o">{</span>
                <span class="nx">selector</span> <span class="o">=</span> <span class="nx">selector</span><span class="o">.</span><span class="nx">replace</span><span class="o">(</span><span class="nx">Selector</span><span class="o">.</span><span class="nx">_re</span><span class="o">.</span><span class="nx">attr</span><span class="o">,</span> <span class="s1">&#39;REPLACED_ATTRIBUTE&#39;</span><span class="o">);</span>
            <span class="o">}</span>

            <span class="k">for</span> <span class="o">(</span><span class="nx">re</span> <span class="k">in</span> <span class="nx">shorthand</span><span class="o">)</span> <span class="o">{</span>
                <span class="k">if</span> <span class="o">(</span><span class="nx">shorthand</span><span class="o">.</span><span class="nx">hasOwnProperty</span><span class="o">(</span><span class="nx">re</span><span class="o">))</span> <span class="o">{</span>
                    <span class="nx">selector</span> <span class="o">=</span> <span class="nx">selector</span><span class="o">.</span><span class="nx">replace</span><span class="o">(</span><span class="nx">Selector</span><span class="o">.</span><span class="nx">_getRegExp</span><span class="o">(</span><span class="nx">re</span><span class="o">,</span> <span class="s1">&#39;gi&#39;</span><span class="o">),</span> <span class="nx">shorthand</span><span class="o">[</span><span class="nx">re</span><span class="o">]);</span>
                <span class="o">}</span>
            <span class="o">}</span>

            <span class="k">if</span> <span class="o">(</span><span class="nx">attrs</span><span class="o">)</span> <span class="o">{</span>
                <span class="k">for</span> <span class="o">(</span><span class="nx">i</span> <span class="o">=</span> <span class="m">0</span><span class="o">,</span> <span class="nx">len</span> <span class="o">=</span> <span class="nx">attrs</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">len</span><span class="o">;</span> <span class="o">++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
                    <span class="nx">selector</span> <span class="o">=</span> <span class="nx">selector</span><span class="o">.</span><span class="nx">replace</span><span class="o">(</span><span class="s1">&#39;REPLACED_ATTRIBUTE&#39;</span><span class="o">,</span> <span class="nx">attrs</span><span class="o">[</span><span class="nx">i</span><span class="o">]);</span>
                <span class="o">}</span>
            <span class="o">}</span>
            <span class="k">return</span> <span class="nx">selector</span><span class="o">;</span>
        <span class="o">}</span>
    <span class="o">};</span>

<span class="nx">Y</span><span class="o">.</span><span class="nx">mix</span><span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">Selector</span><span class="o">,</span> <span class="nx">SelectorCSS2</span><span class="o">,</span> <span class="kc">true</span><span class="o">);</span>

<span class="c">// only override native when not supported</span>
<span class="c"></span><span class="k">if</span> <span class="o">(!</span><span class="nx">Y</span><span class="o">.</span><span class="nx">Selector</span><span class="o">.</span><span class="nx">_supportsNative</span><span class="o">())</span> <span class="o">{</span>
    <span class="nx">Y</span><span class="o">.</span><span class="nx">Selector</span><span class="o">.</span><span class="nx">query</span> <span class="o">=</span> <span class="nx">Selector</span><span class="o">.</span><span class="nx">_brute</span><span class="o">.</span><span class="nx">query</span><span class="o">;</span>
<span class="o">}</span>
</pre></div>
                    </div>
			</div>
		</div>
		<div class="yui-b">
            <div class="nav">

                    <div id="moduleList" class="module">
                        <h4>Modules</h4>
                        <ul class="content">
                                <li class=""><a href="module_anim.html" title="anim">anim</a></li>
                                <li class=""><a href="module_attribute.html" title="attribute">attribute</a></li>
                                <li class=""><a href="module_base.html" title="base">base</a></li>
                                <li class=""><a href="module_cache.html" title="cache">cache</a></li>
                                <li class=""><a href="module_classnamemanager.html" title="classnamemanager">classnamemanager</a></li>
                                <li class=""><a href="module_collection.html" title="collection">collection</a></li>
                                <li class=""><a href="module_console.html" title="console">console</a></li>
                                <li class=""><a href="module_console-filters.html" title="console-filters">console-filters</a></li>
                                <li class=""><a href="module_cookie.html" title="cookie">cookie</a></li>
                                <li class=""><a href="module_dataschema.html" title="dataschema">dataschema</a></li>
                                <li class=""><a href="module_datasource.html" title="datasource">datasource</a></li>
                                <li class=""><a href="module_datatype.html" title="datatype">datatype</a></li>
                                <li class=""><a href="module_dd.html" title="dd">dd</a></li>
                                <li class="selected"><a href="module_dom.html" title="dom">dom</a></li>
                                <li class=""><a href="module_dump.html" title="dump">dump</a></li>
                                <li class=""><a href="module_event.html" title="event">event</a></li>
                                <li class=""><a href="module_event-custom.html" title="event-custom">event-custom</a></li>
                                <li class=""><a href="module_event-simulate.html" title="event-simulate">event-simulate</a></li>
                                <li class=""><a href="module_history.html" title="history">history</a></li>
                                <li class=""><a href="module_imageloader.html" title="imageloader">imageloader</a></li>
                                <li class=""><a href="module_io.html" title="io">io</a></li>
                                <li class=""><a href="module_json.html" title="json">json</a></li>
                                <li class=""><a href="module_node.html" title="node">node</a></li>
                                <li class=""><a href="module_node-focusmanager.html" title="node-focusmanager">node-focusmanager</a></li>
                                <li class=""><a href="module_node-menunav.html" title="node-menunav">node-menunav</a></li>
                                <li class=""><a href="module_oop.html" title="oop">oop</a></li>
                                <li class=""><a href="module_overlay.html" title="overlay">overlay</a></li>
                                <li class=""><a href="module_plugin.html" title="plugin">plugin</a></li>
                                <li class=""><a href="module_profiler.html" title="profiler">profiler</a></li>
                                <li class=""><a href="module_queue.html" title="queue">queue</a></li>
                                <li class=""><a href="module_slider.html" title="slider">slider</a></li>
                                <li class=""><a href="module_stylesheet.html" title="stylesheet">stylesheet</a></li>
                                <li class=""><a href="module_substitute.html" title="substitute">substitute</a></li>
                                <li class=""><a href="module_test.html" title="test">test</a></li>
                                <li class=""><a href="module_widget.html" title="widget">widget</a></li>
                                <li class=""><a href="module_widget-position.html" title="widget-position">widget-position</a></li>
                                <li class=""><a href="module_widget-position-ext.html" title="widget-position-ext">widget-position-ext</a></li>
                                <li class=""><a href="module_widget-stack.html" title="widget-stack">widget-stack</a></li>
                                <li class=""><a href="module_widget-stdmod.html" title="widget-stdmod">widget-stdmod</a></li>
                                <li class=""><a href="module_yui.html" title="yui">yui</a></li>
                        </ul>
                    </div>

                    <div id="classList" class="module">
                        <h4>Classes</h4>
                        <ul class="content">
                                <li class=""><a href="DOM.html" title="DOM">DOM</a></li>
                                <li class=""><a href="Selector.html" title="Selector">Selector</a></li>
                        </ul>
                    </div>

                    <div id="fileList" class="module">
                        <h4>Files</h4>
                        <ul class="content">        
                                <li class=""><a href="color.js.html" title="color.js">color.js</a></li>
                                <li class=""><a href="dom-class.js.html" title="dom-class.js">dom-class.js</a></li>
                                <li class=""><a href="dom-ie-style.js.html" title="dom-ie-style.js">dom-ie-style.js</a></li>
                                <li class=""><a href="dom-region.js.html" title="dom-region.js">dom-region.js</a></li>
                                <li class=""><a href="dom-screen.js.html" title="dom-screen.js">dom-screen.js</a></li>
                                <li class=""><a href="dom-style.js.html" title="dom-style.js">dom-style.js</a></li>
                                <li class=""><a href="dom.js.html" title="dom.js">dom.js</a></li>
                                <li class="selected"><a href="selector-css2.js.html" title="selector-css2.js">selector-css2.js</a></li>
                                <li class=""><a href="selector-css3.js.html" title="selector-css3.js">selector-css3.js</a></li>
                                <li class=""><a href="selector-native.js.html" title="selector-native.js">selector-native.js</a></li>
                        </ul>
                    </div>





            </div>
		</div>
	</div>
	<div id="ft">
        <hr />
        Copyright &copy; 2009 Yahoo! Inc. All rights reserved.
	</div>
</div>
<script type="text/javascript">
    ALL_YUI_PROPS = [{"access": "", "host": "DOM", "name": "addClass", "url": "DOM.html#method_addClass", "type": "method"}, {"access": "", "host": "DOM", "name": "addHTML", "url": "DOM.html#method_addHTML", "type": "method"}, {"access": "private", "host": "DOM", "name": "_bruteContains", "url": "DOM.html#method__bruteContains", "type": "method"}, {"access": "", "host": "DOM", "name": "byId", "url": "DOM.html#method_byId", "type": "method"}, {"access": "", "host": "DOM", "name": "contains", "url": "DOM.html#method_contains", "type": "method"}, {"access": "", "host": "DOM", "name": "create", "url": "DOM.html#method_create", "type": "method"}, {"access": "", "host": "DOM", "name": "docHeight", "url": "DOM.html#method_docHeight", "type": "method"}, {"access": "", "host": "DOM", "name": "docScrollX", "url": "DOM.html#method_docScrollX", "type": "method"}, {"access": "", "host": "DOM", "name": "docScrollY", "url": "DOM.html#method_docScrollY", "type": "method"}, {"access": "", "host": "DOM", "name": "docWidth", "url": "DOM.html#method_docWidth", "type": "method"}, {"access": "", "host": "DOM", "name": "elementByAxis", "url": "DOM.html#method_elementByAxis", "type": "method"}, {"access": "", "host": "DOM", "name": "getAttibute", "url": "DOM.html#method_getAttibute", "type": "method"}, {"access": "", "host": "DOM", "name": "getComputedStyle", "url": "DOM.html#method_getComputedStyle", "type": "method"}, {"access": "private", "host": "DOM", "name": "_getDoc", "url": "DOM.html#method__getDoc", "type": "method"}, {"access": "private", "host": "DOM", "name": "_getRegExp", "url": "DOM.html#method__getRegExp", "type": "method"}, {"access": "", "host": "DOM", "name": "getStyle", "url": "DOM.html#method_getStyle", "type": "method"}, {"access": "", "host": "DOM", "name": "getText", "url": "DOM.html#method_getText", "type": "method"}, {"access": "private", "host": "DOM", "name": "_getWin", "url": "DOM.html#method__getWin", "type": "method"}, {"access": "", "host": "DOM", "name": "getX", "url": "DOM.html#method_getX", "type": "method"}, {"access": "", "host": "DOM", "name": "getXY", "url": "DOM.html#method_getXY", "type": "method"}, {"access": "", "host": "DOM", "name": "getY", "url": "DOM.html#method_getY", "type": "method"}, {"access": "", "host": "DOM", "name": "hasClass", "url": "DOM.html#method_hasClass", "type": "method"}, {"access": "", "host": "DOM", "name": "inDoc", "url": "DOM.html#method_inDoc", "type": "method"}, {"access": "", "host": "Selector", "name": "inRegion", "url": "Selector.html#method_inRegion", "type": "method"}, {"access": "", "host": "DOM", "name": "insertAfter", "url": "DOM.html#method_insertAfter", "type": "method"}, {"access": "", "host": "DOM", "name": "insertBefore", "url": "DOM.html#method_insertBefore", "type": "method"}, {"access": "", "host": "Selector", "name": "intersect", "url": "Selector.html#method_intersect", "type": "method"}, {"access": "", "host": "Selector", "name": "inViewportRegion", "url": "Selector.html#method_inViewportRegion", "type": "method"}, {"access": "", "host": "Selector", "name": "operators", "url": "Selector.html#property_operators", "type": "property"}, {"access": "", "host": "Selector", "name": "PARENT_NODE", "url": "Selector.html#property_PARENT_NODE", "type": "property"}, {"access": "", "host": "Selector", "name": "query", "url": "Selector.html#method_query", "type": "method"}, {"access": "", "host": "Selector", "name": "region", "url": "Selector.html#method_region", "type": "method"}, {"access": "", "host": "DOM", "name": "removeClass", "url": "DOM.html#method_removeClass", "type": "method"}, {"access": "", "host": "DOM", "name": "replaceClass", "url": "DOM.html#method_replaceClass", "type": "method"}, {"access": "", "host": "DOM", "name": "setAttibute", "url": "DOM.html#method_setAttibute", "type": "method"}, {"access": "", "host": "DOM", "name": "setStyle", "url": "DOM.html#method_setStyle", "type": "method"}, {"access": "", "host": "DOM", "name": "setStyles", "url": "DOM.html#method_setStyles", "type": "method"}, {"access": "", "host": "DOM", "name": "setText", "url": "DOM.html#method_setText", "type": "method"}, {"access": "", "host": "DOM", "name": "setX", "url": "DOM.html#method_setX", "type": "method"}, {"access": "", "host": "DOM", "name": "setXY", "url": "DOM.html#method_setXY", "type": "method"}, {"access": "", "host": "DOM", "name": "setY", "url": "DOM.html#method_setY", "type": "method"}, {"access": "", "host": "Selector", "name": "shorthand", "url": "Selector.html#property_shorthand", "type": "property"}, {"access": "", "host": "DOM", "name": "toggleClass", "url": "DOM.html#method_toggleClass", "type": "method"}, {"access": "", "host": "Selector", "name": "_tokenize", "url": "Selector.html#method__tokenize", "type": "method"}, {"access": "", "host": "Selector", "name": "viewportRegion", "url": "Selector.html#method_viewportRegion", "type": "method"}, {"access": "", "host": "DOM", "name": "winHeight", "url": "DOM.html#method_winHeight", "type": "method"}, {"access": "", "host": "DOM", "name": "winWidth", "url": "DOM.html#method_winWidth", "type": "method"}];
</script>
</body>
</html>
